var http = require('http');
var request = require('request');
var co = require('co')
var thunkify = require('thunkify');


var start = co(function *() {
  var request = require('request');
  var readFile = thunkify(request);
  var da = yield readFile('http://www.baidu.com');
  console.log(da);
	// request('http://www.baidu.com', function (error, res, body) {
	//   console.log('error:', error); // Print the error if one occurred
	//   console.log('statusCode:', res && res.statusCode); // Print the response status code if a response was received
	//   console.log('body:', body); // Print the HTML for the Google homepage.
	  
	// });
});


http.createServer(function (request, response) {

	// 发送 HTTP 头部 
	// HTTP 状态值: 200 : OK
	// 内容类型: text/plain
	response.writeHead(200, {'Content-Type': 'text/plain'});
	
    start();
     // console.log(data);
     // response.end("data");

	// 发送响应数据 "Hello World"
	
}).listen(8888);

// 终端打印如下信息
console.log('Server running at http://127.0.0.1:8888/');